import request from '@/utils/request'
import { AddNewData, UpdateRoles, UserData, getRole } from './type'
enum API {
  GETPAGEOFUSER_URL = '/admin/acl/user/',
  ADDNEWUSER_URL = '/admin/acl/user/save',
  UPDATEUSER_URL = '/admin/acl/user/update',
  ASSIGNROLES_URL = '/admin/acl/user/toAssign/',
  UPDATEROLES_URL = '/admin/acl/user/doAssignRole',
  DELETEADMINUSER_URL = '/admin/acl/user/remove/',
  ANYADMINUSER_URL = '/admin/acl/user/batchRemove',
}
//获取用户信息分页
export const getPageOfUserInfo = (
  page: number,
  limit: number,
  username?: string,
  name?: string,
) =>
  request.get<any, UserData>(API.GETPAGEOFUSER_URL + `${page}/${limit}`, {
    params: {
      username,
      name,
    },
  })
// 添加新用户

// 修改用户信息
export const reqUpdateOrAddUser = (data: AddNewData) => {
  if (data.id == '') {
    return request.post<any, any>(API.ADDNEWUSER_URL, data)
  } else {
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  }
}
//获取角色信息
export const reqGetRoles = (adminId: number) =>
  request.get<any, getRole>(API.ASSIGNROLES_URL + adminId)
//修改角色信息
export const reqUpdateRoles = (data: UpdateRoles) =>
  request.post<any, any>(API.UPDATEROLES_URL, data)
export const reqDeleteUser = (id: number) =>
  request.delete<any, any>(API.DELETEADMINUSER_URL + id)
export const reqAnyDeleteUser = (idList: number[]) =>
  request.delete<any, any>(API.ANYADMINUSER_URL, { data: idList })
